/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import common.Stato;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;

/**
 *
 * @author Antonio
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Account.isRegistrato", query = "SELECT a FROM Account a WHERE a.email=?1"),
    @NamedQuery(name = "account.exist", query = "SELECT a From Account a WHERE a.id=?1"),
    @NamedQuery(name = "account.ottieniPersona", query = "SELECT p FROM Account a, Persona p WHERE a.email=?1 AND a.persona = p")
})
public class Account implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable = false, unique = true)
    private String email;
    @Column(nullable = false)
    private String password;
    private Date dataRegistrazione;
    private Stato stato;
    @OneToOne(mappedBy = "account")
    private Persona persona;

    public Persona getPersona() {
        return persona;
    }

    public void setPersona(Persona persona) {
        this.persona = persona;
    }

    /**
     * Get the value of stato
     *
     * @return the value of stato
     */
    public Stato getStato() {
        return stato;
    }

    /**
     * Set the value of stato
     *
     * @param stato new value of stato
     */
    public void setStato(Stato stato) {
        this.stato = stato;
    }

    /**
     * Get the value of dataRegistrazione
     *
     * @return the value of dataRegistrazione
     */
    public Date getDataRegistrazione() {
        return dataRegistrazione;
    }

    /**
     * Set the value of dataRegistrazione
     *
     * @param dataRegistrazione new value of dataRegistrazione
     */
    public void setDataRegistrazione(Date dataRegistrazione) {
        this.dataRegistrazione = dataRegistrazione;
    }

    /**
     * Get the value of password
     *
     * @return the value of password
     */
    public String getPassword() {
        return password;
    }

    /**
     * Set the value of password
     *
     * @param password new value of password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * Get the value of email
     *
     * @return the value of email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Set the value of email
     *
     * @param email new value of email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return id + "," + email;
    }
}
